package com.intelligencesoft.pss.dao;

import java.util.List;

import org.springframework.stereotype.Repository;
import org.springframework.util.StringUtils;

import com.intelligencesoft.pss.entity.base.SysMenu;


@Repository
public class SysMenuDao extends BaseDao<SysMenu>{
	
	public List<SysMenu> getSysMenusByParentId(String parentId){
		if(StringUtils.isEmpty(parentId)){
			return getFirstLevelMenu();
		}else{
			StringBuilder hql = new StringBuilder();
			hql.append("FROM SysMenu sm WHERE sm.parentId = ? ");
			String value = parentId;
			return (List<SysMenu>)this.getHibernateTemplate().find(hql.toString(), value);
		}
	}
	
	private  List<SysMenu> getFirstLevelMenu(){
		String hql = "FROM SysMenu sm WHERE sm.parentId IS NULL ORDER BY sm.menuId";
		return (List<SysMenu>)this.getHibernateTemplate().find(hql);
	}
}
